<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    
    public function index()
    {	
    	$this->display();
    }

    public function checkdata()
    {
    	//var_dump($_POST);
    	
    	//用户名错误时返回JSON
    	$res = D('user')->checkUser(I('post.username'));
    	if (!$res) {
    		$arr = array(
    				'error'=>1,
    				'info'=>'用户名错误',
    			);
    		echo json_encode($arr);
    		exit;
    	}

    	//密码错误时返回JSON
    	$res = D('user')->checkPassword(I('post.username'),I('post.password'));
    	if (!$res) {
    		$arr = array(
    				'error'=>1,
    				'info'=>'密码错误',
    			);
    		echo json_encode($arr);
    		exit;
    	}

    	//验证码错误时返回JSON
    	$res = D('user')->check_verify(I('post.verifycode'));
    	if (!$res) {
    		$arr = array(
    				'error'=>1,
    				'info'=>'验证码错误,请重新输入',
    			);
    		echo json_encode($arr);
    		exit;
    	}
        
        $_SESSION['username']=I('post.username');

    	//所有验证都正确时
    	$arr = array(
				'error'=>0,
				'info'=>'登陆成功,点击确定为您跳转到后台首页',
			);
		echo json_encode($arr);



    }

    //生成验证码
    public function verify()
    {
    	$Verify = new \Think\Verify();
		$Verify->fontSize = 33;
		$Verify->length   = 4;
		$Verify->useNoise = false;
		$Verify->entry();

	}

	






}